package setting

import (
	"github.com/go-ini/ini"
	"github.com/gookit/color"
)

//读取配置

type Database struct {
	Username    string
	Password    string
	Host        string
	DbName      string
	TablePrefix string
}

var DatabaseSetting = &Database{}

var cfg *ini.File

func Setup() {
	var err error
	cfg, err = ini.Load("conf/app.ini")
	if err != nil {
		color.Error.Printf("load conf/app.ini err: %v\n", err)
	}

	mapTo("database", DatabaseSetting)

	color.Info.Println(DatabaseSetting)
}

func mapTo(section string, v interface{}) {
	err := cfg.Section(section).MapTo(v)
	if err != nil {
		color.Error.Printf("map to err: %v\n", err)
	}
}
